function DialogManager(){
	var fn = this;
	
	fn.init = function(){
		fn.overlayContainer = $(".ui-overlay-container");
		fn.dialogContainer = $(".ui-dialog-container");
		fn.create();
	},
	
	fn.create = function(){
		//header
		var groupHeader = $("<div></div>").addClass("ui-dialog-header");
		fn.icon = $("<div></div>").addClass("ui-dialog-header-icon");
		fn.title = $("<div></div>").addClass("ui-dialog-header-title");
		groupHeader.append(fn.icon);
		groupHeader.append(fn.title);
		
		//content
		var groupContent = $("<div></div>").addClass("ui-dialog-content");
		fn.message = $("<div></div>").addClass("ui-dialog-content-message");
		fn.input = $("<input type='textbox'/>").addClass("ui-dialog-content-textbox");
		groupContent.append(fn.message);
		groupContent.append(fn.input);
		
		//button
		var groupButton = $("<div></div>").addClass("ui-dialog-button");
		fn.okButton = $("<div>" + I18n["ok"] + "</div>").addClass("ui-dialog-button-ok");
		fn.cancelButton = $("<div>" + I18n["cancel"] + "</div>").addClass("ui-dialog-button-cancel");
		groupButton.append(fn.okButton);
		groupButton.append(fn.cancelButton);
		
		fn.dialogContainer.append(groupHeader);
		fn.dialogContainer.append(groupContent);
		fn.dialogContainer.append(groupButton);
	},
	
	fn.showErrorMessage = function(msg, successCallback, failCallback){
		fn.icon.addClass("ui-dialog-error");
		fn.title.html("<span>" + I18n["error"] + "</span>");
		fn.message.html("<span>" + msg + "</span>");
		fn.input.hide();
		fn.okButton.on("click touchend", function(){
			fn.hideMessage();
			if(successCallback){
				successCallback();
			}
		});
		
		fn.cancelButton.on("click touchend", function(){
			fn.hideMessage();
			failCallback();
		});
		
		if(failCallback == undefined){
			fn.okButton.addClass("center");
			fn.cancelButton.hide();
		}
		
		fn.showMessage();
	},
	
	fn.showInfoMessage = function(msg){
		fn.icon.addClass("ui-dialog-info");
		fn.title.html("<span>" + I18n["notify"] + "</span>");
		fn.message.html("<span>" + msg + "</span>");
		fn.input.hide();
		fn.okButton.on("click touchend", function(){
			fn.hideMessage();
		});
		fn.okButton.addClass("center");
		fn.cancelButton.hide();
		
		fn.showMessage();
	},
	
	fn.showConfirmMessage = function(msg, successCallback, failCallback){
		fn.icon.addClass("ui-dialog-confirm");
		fn.title.html("<span>" + I18n["confirm"] + "</span>");
		fn.message.html("<span>" + msg + "</span>");
		fn.input.hide();
		fn.okButton.on("click touchend", function(){
			fn.hideMessage();
			successCallback();
		});
		
		fn.cancelButton.on("click touchend", function(){
			fn.hideMessage();
			failCallback();
		});
		
		fn.showMessage();
	},
	
	fn.showPromtMessage = function(msg, successCallback, failCallback){
		fn.icon.addClass("ui-dialog-confirm");
		fn.title.html("<span>" + I18n["confirm"] + "</span>");
		fn.message.html("<span>" + msg + "</span>");
		fn.okButton.on("click touchend", function(){
			var val = fn.input.val();
			if(val === ""){
				fn.input.focus();
				return;
			}
			fn.hideMessage();
			successCallback(val);
		});
		
		fn.cancelButton.on("click touchend", function(){
			if(failCallback){
				failCallback();
			}
			fn.hideMessage();
		});
		
		fn.showMessage();
	},
	
	fn.showWaitingMessage = function(){
		fn.icon.addClass("ui-dialog-info");
		fn.title.html("<span>" + I18n["joining a room"] + "</span>");
		fn.message.html("<span>" + I18n["please wait"] + "</span>");
		fn.input.hide();
		fn.okButton.hide();
		fn.cancelButton.hide();
		
		fn.showMessage();
	},
	
	fn.showMessage = function(){
		$(".ui-dialog").show();
		fn.overlayContainer.show();
		fn.dialogContainer.show();
	},
	
	fn.hideMessage = function(){
		fn.icon.removeClass("ui-dialog-error");
		fn.icon.removeClass("ui-dialog-info");
		fn.icon.removeClass("ui-dialog-confirm");
		
		fn.title.html("");
		fn.message.html("");
		fn.input.val("");
		
		fn.okButton.removeClass("center");
		fn.okButton.show();
		fn.cancelButton.show();
		
		fn.okButton.off("click touchend");
		fn.cancelButton.off("click touchend");
		
		fn.input.show();
		
		$(".ui-dialog").hide();
		fn.overlayContainer.hide();
		fn.dialogContainer.hide();
	}
};